package com.fausto.learnimprint

import com.fausto.learnimprint.core.service.impl.UserService
import com.fausto.learnimprint.utils.JwtUtil
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired

class JwtTokenTests : BlogApplicationTests() {

    @Autowired
    lateinit var jwtUtil: JwtUtil

    @Autowired
    lateinit var userService: UserService

    /**
     *      测试生成Token
     */
    @Test
    fun testToken() {

        val userDetails = userService.loadUserByUsername("admin")

        val token = jwtUtil.generateToken(userDetails)

        println("======================================================")
        println("Token:\t$token")
    }

    @Test
    fun getRoleFromToken() {
        val token =
            "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTY1MDAwNjAyNywiY3JlYXRlZCI6MTY0OTc0NjgyNzU0OSwicm9sZXMiOlsiVVNFUiIsIkFETUlOIl19.5SGOsx_aZFZwSFsOe7EgnSdhqoYtiJeLURat7atph2xfdAjAsklIyiIBRVSlQEAg8BWF1WH-DeGrnS7YkWnnDg"
        jwtUtil.getRolesFromToken(token).forEach(::println)
    }
}